import org.apache.commons.lang.StringUtils;

/**
 * Created by sToa on 2014/12/26.
 */
public class ParserHelper {

    public static String trim = "$";

    public static String trim(String string)
    {
        return trim(string, trim);
    }

    public static String trim(String string, String trim)
    {
        String trimReg = "\\"+trim;
        if (StringUtils.isBlank(trim))
        {
            return string;
        }
        while (string.indexOf(trim)==0)
        {
            string = string.replaceFirst(trimReg, "");
        }
        while (string.endsWith(trim))
        {
            string = string.substring(0, string.length()-1);
        }
        return string;
    }

    public static void main(String[] args) {
        System.out.println(trim("..faf.afa.afa.....", "."));
    }
}
